package top.withu.gaof.freehope.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice.This;
import top.withu.gaof.freehope.annotate.PassCheck;
import top.withu.gaof.freehope.dao.ArticleContentDao;
import top.withu.gaof.freehope.model.ArticleContent;
import top.withu.gaof.freehope.model.ArticleModel;
import top.withu.gaof.freehope.res.ArticleRes;
import top.withu.gaof.freehope.service.ArticleService;
import top.withu.gaof.freehope.service.impl.ArticleServiceImpl;
import top.withu.gaof.freehope.vo.ArticleVo;

import javax.annotation.Resource;

@RestController
@Api("文章分享模块")
@RequestMapping("/article")
public class ArticleController {
	

	@Autowired
	private ArticleService articleService;

	@Resource
	private ArticleContentDao articleContentDao;

	@GetMapping("/docs")
	@PassCheck
	@ApiOperation(value = "获取所有文章", notes = "获取未失效文章", tags = "doc module")
	public List<ArticleRes> getDocs() {
		return articleService.getAll();
	}
	
	@PostMapping("/doc")
	@PassCheck
	@ApiOperation(value = "插入更新文档", notes = "插入更新文档", tags = "doc module")
	public int updateDoc(@RequestBody
			ArticleVo articleVo) {
		return articleService.updateArticle(articleVo);
	}
	
	@GetMapping("/doc")
	@PassCheck
	@ApiOperation(value = "获取当前文档", notes = "获取当前文档", tags = "doc module")
	public ArticleContent getDoc(@RequestParam String id) {
		return articleContentDao.findByArticleId(Integer.valueOf(id));
	}


}
